package com.contract.spirit.ui.login

import androidx.databinding.ObservableField
import androidx.lifecycle.MutableLiveData
import com.contract.commonlib.base.BaseViewModel
import com.contract.commonlib.http.ext.request
import com.contract.commonlib.http.status.ResultState
import com.contract.spirit.bean.response.RegisterStatusResponse
import com.contract.spirit.config.SmsCodeConfig
import com.contract.spirit.func.net.rxApi

/**
 * @author: witness
 * created: 2021/9/18
 * desc:
 */
class LoginViewModel : BaseViewModel() {
    val loginObservable = MutableLiveData<ResultState<String>>()
    val emsCodeObservel = MutableLiveData<ResultState<String>>()
    val registeCheckObservable = MutableLiveData<ResultState<RegisterStatusResponse>>()
    var phoneNumber = ObservableField<String>()
    var smsCode = ObservableField<String>()

    fun login(inviteCode: String?) {
        request(
            { rxApi.login(phoneNumber.get().toString(), smsCode.get().toString(), inviteCode)},
            loginObservable,
            isShowDialog = true,
            loadingMessage = true
        )
    }

    fun checkRegister(phone: String) {
        request(
            {rxApi.checkRegister(phone) },
            registeCheckObservable,
            isShowDialog = true,
            loadingMessage = true
        )
    }

    fun getMmsCode() {
        request(
            { rxApi.getEmsCode(phoneNumber.get().toString(), SmsCodeConfig.REGISTER) },
            emsCodeObservel,
            isShowDialog = true,
            loadingMessage = true
        )
    }
}